<template>
  <el-container class="home_container">
  <el-header>
   <div>
     <img :src="homeImg" alt="">
     <span>后台管理系统</span>
   </div>
   <el-button type="info">退出</el-button>
  </el-header>
  <el-container>
    <el-aside :width="flag?'42px':'200px'">
      <div class="toggle-button" @click="toggleCollapse">|||</div>
      <el-menu
      :collapse-transition='false'
      unique-opened
      :collapse="flag"
      router
      :default-active="activePath"
      class="el-menu-vertical-demo"
      background-color="#333744"
      text-color="#fff"
      active-text-color="#409eff">
      <el-submenu :index="item.id+''" v-for="(item) in MenuList" :key="item.id">
        <template slot="title">
          <i :class="iconObj[item.id]"></i>
          <span>{{item.authName}}</span>
        </template>
         <el-menu-item :index="'/'+val.path" v-for="(val) in item.children" :key="val.id"
          @click="handleActive('/'+val.path)">
           <i class="iconfont icon-menu-line"></i>
          <span>{{val.authName}}</span>
         </el-menu-item>
      </el-submenu>
    </el-menu>
    </el-aside>
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</el-container>

</template>

<script>

export default {
  data () {
    return {
      homeImg: require('../assets/home.png'),
      MenuList: [],
      iconObj: {
        125: 'iconfont icon-yonghu1',
        103: 'iconfont icon-ic_opt_feature',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-dingdan',
        145: 'iconfont icon-icon_website_huabanfuben'
      },
      flag: false,
      activePath: ''
    }
  },
  mounted () {
    this.getMenuList()
    this.activePath = sessionStorage.getItem('activePath')
  },
  methods: {
    async  getMenuList () {
      const { data: res } = await this.$axios.get('menus')
      this.MenuList = res.data
    },
    toggleCollapse () {
      this.flag = !this.flag
    },
    handleActive (activePath) {
      this.activePath = activePath
      sessionStorage.setItem('activePath', activePath)
    }
  }
}
</script>
<style scoped lang="less">
.toggle-button {
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  text-align: center;
  letter-spacing: 0.2em;
}
.home_container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 0;
  >div {
    display: flex;
    align-items: center;
    color: #fff;
    img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      margin-right: 15px;
    }
  }
}
.el-aside {
 background-color: #333744;
 .el-menu {
   border-right: none!important;
 }
}
.el-main {
  background-color: #EAEDF1;
}
.iconfont {
  margin-right: 10px;
}
</style>
